class AdSubscription < ActiveRecord::Base
  belongs_to :user
  belongs_to :ad

  def self.toggle_subscription(ad_id, user_id)
   unless is_subscriber(ad_id, user_id)
      AdSubscription.create(:ad_id => ad_id, :user_id => user_id)
    else
      AdSubscription.delete(self.find_by_ad_id_and_user_id(ad_id,user_id).id)
    end
  end

  def self.is_subscriber(ad_id, user_id)
    return (self.find_by_ad_id_and_user_id(ad_id,user_id) != nil)
  end
end
